// 请更换为自己的appid
const appId = "wxd4e6c7af049ae5ff";
Page({
    data: {
        appId: "",
        openId: "",
        appName: "课程表"
    },

    onShow() {

        this.setData({
            appId: appId
        })
        var openId = wx.getStorageSync('openId');
        if (openId == null || openId == '') {
            this.getOpenId();
        } else {
            this.setData({
                openId: openId
            })
            this.initKcb();
        }
    },

    onShareAppMessage: function () {

    },

    getOpenId() {
        console.log("获取openId")
        var that = this;
        wx.cloud.callFunction({
            name: 'getOpenid',
            complete: res => {
                console.log(res)
                console.log('云函数获取到的openid:', res.result.openid)
                var openId = res.result.openid;
                wx.setStorageSync("openId", openId);
                that.setData({
                    openId: openId
                })
                that.initKcb();
            }
        })
    },

    initKcb() {
        var appId = this.data.appId;
        var openId = this.data.openId;
        var appName = this.data.appName;
        wx.navigateTo({
            url: 'plugin://kcb-plugin/kcb-page?appId=' + appId + '&openId=' + openId + '&appName=' + appName,
        })
    }
})